package com.bsh.controller.system;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.bsh.service.ModuleService;
import com.bsh.utils.Pager;
import com.mysql.jdbc.StringUtils;

/**
 * @author gsh
 * @since 0.0.1
 * 
 */
@Controller
public class ModuleController {
	private static Logger log = LoggerFactory.getLogger(ModuleController.class);
	@Autowired
	HttpServletRequest request;
    @Autowired
    HttpServletResponse response;
    @Autowired
    HttpSession session;    
    @Autowired
    ModuleService module;
	@Autowired
	private ModuleService moduleService;

	/**
	 * 合作伙办列表
	 */
	@RequestMapping(value = "/system/module/list")
	public ModelAndView moduleList() {
		String userName = request.getParameter("userName") == null ? null : request.getParameter("userName").toString();
		String email = request.getParameter("email") == null ? null : request.getParameter("email").toString();

		ModelAndView mv = new ModelAndView();
		mv.setViewName("/pages/system/ModuleList");

		String pageStr = request.getParameter("pageIndex");
		Integer pageIndex = Integer.parseInt(StringUtils.isNullOrEmpty(pageStr) ? "1" : pageStr);

		String sizeStr = request.getParameter("pageSize");
		Integer pageSize = Integer.parseInt(StringUtils.isNullOrEmpty(sizeStr) ? "10" : sizeStr);

		Pager pager = new Pager(pageIndex, pageSize);
		List<Map<String, Object>> list = moduleService.getPage(pager, userName, email);
		mv.addObject("list", list);
		mv.addObject("pager", pager);
		mv.addObject("userName", userName);
		mv.addObject("email", email);
		return mv;
	} 
	
}
